#ifndef LOGINWIDGET_H
#define LOGINWIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QStackedWidget>
#include "authservice.h"

class LoginWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LoginWidget(AuthService *authService, QWidget *parent = nullptr);
    virtual ~LoginWidget();

signals:
    void loginSucceeded();
    void switchToRegister();
    void switchToForgotPassword();

private slots:
    void onLoginClicked();
    void onRegisterClicked();
    void onForgotPasswordClicked();
    void onLoginSucceeded(const AuthService::UserInfo &userInfo);
    void onLoginFailed(const QString &error);

private:
    void setupUI();
    void setupLoginCard(QWidget *centerCard);
    QWidget* createInputGroup(const QString &icon, const QString &label, const QString &placeholder, QLineEdit *&lineEdit);
    void setUIEnabled(bool enabled);
    void clearForm();
    void applyStyles();

    AuthService *m_authService;

    // UI组件
    QVBoxLayout *m_mainLayout;
    QGroupBox *m_loginGroup;
    QFormLayout *m_formLayout;
    
    QLineEdit *m_usernameEdit;
    QLineEdit *m_passwordEdit;
    QCheckBox *m_rememberCheck;
    QCheckBox *m_showPasswordCheck;
    QPushButton *m_loginButton;
    QPushButton *m_registerButton;
    QPushButton *m_forgotPasswordButton;
    QLabel *m_statusLabel;
    QProgressBar *m_progressBar;
    QLabel *m_titleLabel;
    QLabel *m_logoLabel;

    // 样式
    QString m_primaryColor;
    QString m_secondaryColor;
    QString m_backgroundColor;
    QString m_textColor;
    QString m_errorColor;
    QString m_successColor;
};

#endif // LOGINWIDGET_H
